package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityDrawBinding;
import flc.ast.databinding.ActivityDrawDetailBinding;
import io.reactivex.rxjava3.core.ObservableEmitter;
import stark.common.basic.utils.FastClickUtil;
import stark.common.basic.utils.RxUtil;

public class DrawDetailActivity extends BaseAc<ActivityDrawDetailBinding> {

    public static String imgPath;

    @Override
    protected int onCreate() {
        return R.layout.activity_draw_detail;
    }

    @Override
    protected void initView() {
        mDataBinding.ivDrawDetailBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        mDataBinding.ivDelete.setOnClickListener(this);
        Glide.with(mContext).load(imgPath).into(mDataBinding.ivDrawDetail);
    }

    @Override
    protected void onClickCallback(View v) {
        if (FastClickUtil.isFastClick()) return;
        switch (v.getId()) {
            case R.id.ivDelete:
                delete();
                break;
        }
    }

    @Override
    protected void initData() {

    }

    // 清空
    private void delete() {
        RxUtil.create(new RxUtil.Callback<String>() {

            @Override
            public void doBackground(ObservableEmitter<String> emitter) {
                FileUtils.delete(imgPath);
                emitter.onNext("");
            }

            @Override
            public void accept(String path) {
                dismissDialog();
                ToastUtils.showShort(R.string.delete_suc);
                finish();
            }
        });
    }

}